// import Pool from './base/pool';
import { SCREEN_HEIGHT, SCREEN_WIDTH } from "./render";

let instance;
const gameIndex = wx.getStorageSync("GameIndex") || 1
/**
 * 全局状态管理器
 * 负责管理游戏的状态，包括帧数、分数、子弹、敌人和动画等
 */
export default class DataBus {
  // 直接在类中定义实例属性
  GameIndex = gameIndex
  cardsData = []; // 卡片数据数据组
  slotCardsdData = []; // 卡槽中的卡片
  selectedData = []; // 点击选中的卡片
  isGameOver = false; // 游戏是否结束

  constructor() {
    // 确保单例模式
    if (instance) return instance;

    instance = this;
  }

  // 重置游戏状态
  reset() {
    this.GameIndex = gameIndex;
    this.cardsData = []; // 卡片数据数据组
    this.slotCardsdData = []; // 卡槽中的卡片
    this.selectedData = []; // 点击选中的卡片
    this.isGameOver = false; // 游戏是否结束 
  }

  // 游戏结束
  gameOver() {
    this.isGameOver = true;
  }

  // /**
  //  * 回收敌人，进入对象池
  //  * 此后不进入帧循环
  //  * @param {Object} enemy - 要回收的敌人对象
  //  */
  // removeEnemy(enemy) {
  //   const temp = this.enemys.splice(this.enemys.indexOf(enemy), 1);
  //   if (temp) {
  //     this.pool.recover("enemy", enemy); // 回收敌人到对象池
  //   }
  // }

  // /**
  //  * 回收子弹，进入对象池
  //  * 此后不进入帧循环
  //  * @param {Object} bullet - 要回收的子弹对象
  //  */
  // removeBullets(bullet) {
  //   const temp = this.bullets.splice(this.bullets.indexOf(bullet), 1);
  //   if (temp) {
  //     this.pool.recover("bullet", bullet); // 回收子弹到对象池
  //   }
  // }
}


const grid = {
  rows: 20,
  cols: 20,

  width: 0,
  height: 0,
  left: GameGlobal.px2dpr(10),
  right: GameGlobal.px2dpr(10),
  top: GameGlobal.px2dpr(100),
  bottom: 0,
  itemWidth: 0,
  itemHeight: 0,
};

grid.itemWidth = Math.floor(
  Math.floor(SCREEN_WIDTH - grid.left - grid.right) / grid.cols
);
grid.itemHeight = grid.itemWidth;
grid.width = grid.itemWidth * grid.cols;
grid.height = grid.width;
grid.left = Math.floor((SCREEN_WIDTH - grid.width) / 2);


const card = {
  width: grid.itemWidth * 2,
  height: grid.itemHeight * 2,
};
const slot = {
  width: 0,
  height: 0,
  left: 0,
  top: 0,
  bottom: 100,
  itemGap: GameGlobal.px2dpr(6),
};

slot.width = card.width * 7 + slot.itemGap * 8 + GameGlobal.px2dpr(32);
// slot.height = card.height + slot.itemGap * 2;
slot.height = 132 / (500 / slot.width)
slot.top = (SCREEN_HEIGHT - grid.top - grid.height - slot.height - GameGlobal.px2dpr(100)) / 2 + grid.top + grid.height;
slot.left = (SCREEN_WIDTH - slot.width) / 2;


/* card.width = cardwdith
card.height = cardwdith */

GameGlobal.card = card;
GameGlobal.slot = slot;
console.log(GameGlobal.slot, (SCREEN_HEIGHT - grid.top - grid.height - slot.height - 50) / 2, grid.top + grid.height)
GameGlobal.grid = grid;

